<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">

    <el-form-item label="用户业务编号" prop="userCode">
      <el-input v-model="dataForm.userCode" placeholder="用户业务编号"></el-input>
    </el-form-item>
 
    <el-form-item label="用户类型" prop="userType">
      <!-- <el-input v-model="dataForm.userType" placeholder="用户类型"></el-input> -->
      <el-radio v-model="dataForm.userType" label="游客">游客</el-radio>
    <el-radio v-model="dataForm.userType" label="学生">学生</el-radio>
    <el-radio v-model="dataForm.userType" label="教师">教师</el-radio>
    </el-form-item>
    <el-form-item label="用户权限" prop="userPrivilege">
      <!-- <el-input v-model="dataForm.userPrivilege" placeholder="用户权限"></el-input> -->
      <el-radio-group v-model="dataForm.userPrivilege">
      <el-radio-button v-model="dataForm.userPrivilege" label="游客权限"></el-radio-button>
      <el-radio-button v-model="dataForm.userPrivilege" label="学生权限"></el-radio-button>
      <el-radio-button v-model="dataForm.userPrivilege" label="教师权限"></el-radio-button>
    </el-radio-group>
    </el-form-item>
    <el-form-item label="用户名称" prop="userName">
      <el-input v-model="dataForm.userName" placeholder="用户名称"></el-input>
    </el-form-item>
    <el-form-item label="操作时间" prop="lastLoginTime">
      <!-- <el-input v-model="dataForm.lastLoginTime" placeholder="操作时间"></el-input> -->
      <div class="block">
    <el-date-picker
      v-model="dataForm.lastLoginTime"
      type="datetime"
      placeholder="选择日期时间"
      value-format="yyyy-MM-dd HH:mm:ss">
    </el-date-picker>
  </div>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import SingleUpload from "@/components/upload/singleUpload";
  export default {
    components: { SingleUpload },
    data () {
      return {
        visible: false,
        dataForm: {
          logo: "",
          id: 0,
          gmtCreate: '',
          createBy: '',
          gmtModified: '',
          lastModifiedBy: '',
          isDeleted: '',
          sortNo: '',
          version: '',
          userCode: '',
          userType: '',
          userPrivilege: '',
          userName: '',
          lastLoginTime: '',
          isApply: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '记录创建者不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
          ],
          lastModifiedBy: [
            { required: true, message: '记录最后更新人不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(1删除,0未删除)不能为空', trigger: 'blur' }
          ],
          sortNo: [
            { required: true, message: '序号不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          userCode: [
            { required: true, message: '用户业务编号不能为空', trigger: 'blur' }
          ],
          userType: [
            { required: true, message: '用户类型(0_游客,1_学生,2_老师,3_管理员)不能为空', trigger: 'blur' }
          ],
          userPrivilege: [
            { required: true, message: '用户权限不能为空', trigger: 'blur' }
          ],
          userName: [
            { required: true, message: '用户名称不能为空', trigger: 'blur' }
          ],
          lastLoginTime: [
            { required: true, message: '上一次登录时间不能为空', trigger: 'blur' }
          ],
          isApply: [
            { required: true, message: '是否有申请权限(0_否，1_是)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyrecord/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.tIdentifyRecord.gmtCreate
                this.dataForm.createBy = data.tIdentifyRecord.createBy
                this.dataForm.gmtModified = data.tIdentifyRecord.gmtModified
                this.dataForm.lastModifiedBy = data.tIdentifyRecord.lastModifiedBy
                this.dataForm.isDeleted = data.tIdentifyRecord.isDeleted
                this.dataForm.sortNo = data.tIdentifyRecord.sortNo
                this.dataForm.version = data.tIdentifyRecord.version
                this.dataForm.userCode = data.tIdentifyRecord.userCode
                this.dataForm.userType = data.tIdentifyRecord.userType
                this.dataForm.userPrivilege = data.tIdentifyRecord.userPrivilege
                this.dataForm.userName = data.tIdentifyRecord.userName
                this.dataForm.lastLoginTime = data.tIdentifyRecord.lastLoginTime
                this.dataForm.isApply = data.tIdentifyRecord.isApply
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyrecord/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'createBy': this.dataForm.createBy,
                'gmtModified': this.dataForm.gmtModified,
                'lastModifiedBy': this.dataForm.lastModifiedBy,
                'isDeleted': this.dataForm.isDeleted,
                'sortNo': this.dataForm.sortNo,
                'version': this.dataForm.version,
                'userCode': this.dataForm.userCode,
                'userType': this.dataForm.userType,
                'userPrivilege': this.dataForm.userPrivilege,
                'userName': this.dataForm.userName,
                'lastLoginTime': this.dataForm.lastLoginTime,
                'isApply': this.dataForm.isApply
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
